﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Artemis.Core;
using System.Data.Common;
using System.Data.Common.CommandTrees;

namespace Artemis.Data.ProxyProvider
{
    class ProxyCommandDefinition : DbCommandDefinitionWrapper
    {
        internal ProxyCommandDefinition(DbCommandDefinition wrappedCommandDefinition, DbCommandTree commandTree)
            : base(wrappedCommandDefinition, commandTree, (cmd, def) => new ProxyCommand(cmd, def))
        {
            
        }

        internal ProxyCommandDefinition():this(null,null) { 
        }
        
        public override DbCommand CreateCommand()
        {
            return new ProxyCommand(WrappedCommandDefinition.CreateCommand(), this);
        }

        bool? _isReadOnly;
        public bool IsReadOnly
        {
            get
            {
                if (_isReadOnly.HasValue)
                    return _isReadOnly.Value;
                _isReadOnly = this.CommandTree is DbQueryCommandTree;
                return _isReadOnly.Value;
            }
            set { _isReadOnly = value; }
        }
                
    }
}
